package com.shenmazong.dead.recv;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @author 军哥
 * @version 1.0
 * @description: 死信消息接收
 * @date 2022/2/9 19:09
 */

@Component
@Slf4j
public class RecvMessage {

    @RabbitListener(queues = "dead")
    public void handleMessage(Message message, Channel channel) throws IOException {

        // 获取消息ID
        String messageId = message.getMessageProperties().getMessageId();
        log.warn("messageId:"+messageId);

        // 获取消息内容
        String body = new String(message.getBody());
        log.warn("body:"+body);

        // 手动确认消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
